package com.xuecheng.learning.controller;

import com.xuecheng.commons.model.dto.LearningProgressDto;
import com.xuecheng.commons.model.dto.RecordDto;
import com.xuecheng.commons.model.vo.CourseRecordVo;
import com.xuecheng.commons.model.vo.ResourceVo;
import com.xuecheng.commons.model.vo.ResponseResult;
import org.springframework.web.bind.annotation.*;
import com.xuecheng.learning.service.CourseRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 选课记录前端控制器
 */
@Slf4j
@RestController
public class CourseRecordController {

    @Autowired
    private CourseRecordService  courseRecordService;

    //通过课程发布id查询用户的课程记录
    @GetMapping("/learnedRecords/myCourseRec/{coursePubId}")
    public ResponseResult<CourseRecordVo> findRecordByPubId(@PathVariable("coursePubId") Long coursePubId) {
        return courseRecordService.findRecordByPubId(coursePubId);
    }

    //保存或更新选课记录
    @PostMapping("/courseRecord/saveRecord")
    public ResponseResult saveRecord(@RequestBody RecordDto dto) {
        return courseRecordService.saveRecord(dto);
    }

    //获取课程视频资源地址
    @GetMapping("/learnedRecords/resource-url")
    public ResponseResult<ResourceVo> findPlayUrl(Long coursePubId, Long mediaId, Long teachplanId) {
        return courseRecordService.findPlayUrl(coursePubId,mediaId,teachplanId);
    }

    //保存或更新学习进度
    @PostMapping("/learnedRecords/progress")
    public ResponseResult progress(@RequestBody LearningProgressDto dto) {
        return courseRecordService.progress(dto);
    }
}
